local sk__chanxian = fk.CreateSkill {

  name = "sk__chanxian",

  tags = {},

}



sk__chanxian:addEffect("active", {
  name = "sk__chanxian",
  anim_type = "control",
  card_num = 0,
  target_num = 2,
  prompt = function(self, player, selected_cards, selected_targets)
    if #selected_targets == 0 then
      return "#sk__chanxian0:::" .. self.interaction.data
    elseif #selected_targets == 1 then
      return "#sk__chanxian1:" .. selected_targets[1].id .. "::" .. self.interaction.data
    elseif #selected_targets == 2 then
      return "#sk__chanxian2:" .. selected_targets[1].id .. ":" .. selected_targets[2].id .. ":" .. self.interaction.data
    end
  end,
  interaction = function(self)
    return UI.ComboBox { choices = { "hand_card", "Field" } }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(sk__chanxian.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    if #selected == 0 then
      if self.interaction.data == "hand_card" then
        return not to_select:isKongcheng()
      elseif self.interaction.data == "Field" then
        return #to_select:getCardIds("ej") > 0
      end
    elseif #selected == 1 then
      if self.interaction.data == "hand_card" then
        return true
      else
        return selected[1]:canMoveCardsInBoardTo(to_select)
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target1 = effect.tos[1]
    local target2 = effect.tos[2]
    if self.interaction.data == "hand_card" then
      local card = room:askForCardChosen(player, target1, "h", sk__chanxian.name,
        "#sk__chanxian-card:" .. target1.id .. ":" .. target2.id)
      room:moveCardTo(card, Card.PlayerHand, target2, fk.ReasonJustMove, sk__chanxian.name, nil, false, player)
    else
      room:askForMoveCardInBoard(player, target1, target2, sk__chanxian.name, nil, target1)
    end
    if target1.dead or target2.dead or target1:isProhibited(target2, Fk:cloneCard("duel")) then return end
    local use = room:useVirtualCard("duel", nil, target1, target2, sk__chanxian.name)
    if use and use.damageDealt then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if player.dead then return end
        if use.damageDealt[p] and not p:isNude() and not p.dead then
          local card = room:askForCardChosen(player, p, "he", sk__chanxian.name, "#sk__chanxian-prey::" .. p.id)
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, sk__chanxian.name, nil, false, player)
        end
      end
    end
  end,
})

return sk__chanxian
